import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Max value on the top
 */

public class MaxHeap {
    public static void main(String[] args) {
        MaxHeap heap = new MaxHeap();

//        String testString = "6\n" +
//                "Insert 100\n" +
//                "Insert 10\n" +
//                "Extract\n" +
//                "Insert 5\n" +
//                "Insert 50\n" +
//                "Extract";
//        Scanner scanner = new Scanner(testString);

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            String command = scanner.next();
            if ("Insert".equals(command)) {
                heap.insert(scanner.nextInt());
            } else if ("Extract".equals(command)) {
                int maxValue = heap.extract();
                System.out.println(maxValue);
            }
//            System.out.println(heap);
        }
    }

    private List<Integer> list = new ArrayList<Integer>();

    public void insert(int value) {
        list.add(value);
        siftUp(list.size() - 1);
    }

    private void siftUp(int index) {
        if (index == 0) {
            return;
        }

        int parentIndex = parent(index);
        int parentValue = list.get(parentIndex);
        int indexValue = list.get(index);
        if (parentValue < indexValue) {
            swap(index, parentIndex);
            siftUp(parentIndex);
        }
    }

    public int extract() {
        if (list.size() == 1) {
            return list.remove(0);
        }

        int result = list.get(0);
        int lastValue = list.get(list.size() - 1);
        list.remove(list.size() - 1);
        list.set(0, lastValue);
        siftDown(0);
        return result;
    }

    private void siftDown(int index) {
        int leftIndex = left(index);
        int rightIndex = right(index);
        int leftValue;
        int rightValue;

        if (leftIndex < list.size()) {
            leftValue = list.get(leftIndex);
        } else {
            leftValue = Integer.MIN_VALUE;
        }

        if (rightIndex < list.size()) {
            rightValue = list.get(rightIndex);
        } else {
            rightValue = Integer.MIN_VALUE;
        }

        int resultIndex;
        int resultValue;

        if (leftValue > rightValue) {
            resultIndex = leftIndex;
            resultValue = leftValue;
        } else {
            resultIndex = rightIndex;
            resultValue = rightValue;
        }

        if (list.get(index) >= resultValue) {
            return;
        }

        swap(index, resultIndex);
        siftDown(resultIndex);
    }

    private void swap(int index1, int index2) {
        int value1 = list.get(index1);
        int value2 = list.get(index2);
        list.set(index1, value2);
        list.set(index2, value1);
    }

    private int left(int index) {
        return 2 * index;
    }

    private int right(int index) {
        return 2 * index + 1;
    }

    private int parent(int index) {
        return index / 2;
    }

    @Override
    public String toString() {
        return Arrays.toString(list.toArray());
    }
}
